import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:myapp/app/data/entities/key_value_model.dart';
import 'package:myapp/app/modules/brokerinfo/controllers/brokerinfo_controller.dart';
import 'package:myapp/app/theme/app_color.dart';
import 'package:myapp/app/widget/noripple_behavior.dart';

class BrokerInfoItemWidget extends GetView<BrokerinfoController> {
  final int index;

  const BrokerInfoItemWidget(this.index, {Key? key}) : super(key: key);

  _buildTitle(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(left: 5),
      child: Obx(
        () => controller.labels.isEmpty? Container(): Text(
          controller.labels[index],
          style: TextStyle(
            color: AppColor.hex_333,
            fontSize: 16,
            fontWeight: FontWeight.bold,
          ),
        ),
      ),
      decoration: BoxDecoration(
        border: Border(
          left: BorderSide(
            width: 2,
            color: Color(0xff099CD5),
          ),
        ),
      ),
    );
  }

  _buildItem(BuildContext context, KeyValue item) {
    return Container(
      margin: EdgeInsets.only(bottom: 30),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(
            item.key ?? "",
            style: TextStyle(color: AppColor.hex_666, fontSize: 14),
          ),
          Text(
            item.value ?? "-",
            style: TextStyle(
                color: AppColor.hex_333,
                fontSize: 14,
                fontWeight: FontWeight.bold),
          ),
        ],
      ),
    );
  }

  _buildList(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(top: 30),
      child: Obx(
        () => ScrollConfiguration(
          behavior: NoRippleBehavior(),
          child: controller.data.isEmpty? Container(): ListView.builder(
            physics: NeverScrollableScrollPhysics(),
            shrinkWrap: true, //内容包裹
            itemBuilder: (BuildContext context, int itemIndex) {
              print("itemIndex $itemIndex");
              return _buildItem(context, controller.data[index][itemIndex]);
            },
            itemCount: controller.data[index].length,
          ),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: Get.size.width,
      child: ListView(
        shrinkWrap: true,
        physics: NeverScrollableScrollPhysics(),
        children: [
          _buildTitle(context),
          _buildList(context),
        ],
      ),
    );
  }
}
